#!/bin/bash

ES7_HOST="http://localhost:9200"   
ES9_HOST="http://localhost:19200"   

# 批量迁移
curl -s "http://localhost:9200/_cat/indices?v" |grep -v '^health' |  awk '{print $3}' | grep -vE '^\.'  > es7_indices.txt
while IFS= read -r index; do
  if [ -n "$index" ]; then   
    echo "start index : $index"
    curl -X POST "$ES9_HOST/_reindex?wait_for_completion=false" -H "Content-Type: application/json" -d '{
      "source": {
        "remote": {
          "host": "'"$ES7_HOST"'",
		  "socket_timeout": "5m",
	      "connect_timeout": "5m"
        },
        "index": "'"$index"'"
      },
      "dest": {
        "index": "'"$index"'" 
      }
    }'
    echo -e "\nindex $index task has been commited\n"
    sleep 2 
  fi
done < es7_indices.txt




# 当个索引迁移
curl -XPOST 'http://localhost:19200/_reindex?pretty' -H 'Content-Type: application/json' -d'
{
  "source": {
    "remote": {
      "host": "http://远程路径:9200",
	  "socket_timeout": "5m",
	  "connect_timeout": "5m"
    },
    "index": "索引名称"
  },
  "dest": {
    "index": "索引名称"
  }
}'
